package com.jkgh.asin;

import com.jkgh.asin.buffers.DataConsumer;
import com.jkgh.asin.buffers.DataProducer;

public abstract class StateMachine implements DataProducer, DataConsumer {

	private State state;

	protected final void onBytesAvailable() {
		while (true) {
			State previousState = state;
			state.onBytesAvailable();
			if (state == previousState || getBytesAvailable() == 0) {
				break;
			}
		}
	}
	
	public void setCurrentState(State state) {
		this.state = state;
	}
	
	public abstract int getBytesAvailable();
	public abstract void disconnect();
	public abstract void disconnectAfterAllWrites();
}
